﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace PluginPathFinder
{
    public class PathFollowerToPoint : PathFollower
    {
        public override void MoveTo(int pointIndex)
        {
            var targetPos = CastToVec(_pathToFollow[pointIndex]);
            var deltaPos = targetPos - _transform.position;
            if(alignToPath)
            {
                _transform.up = Vector3.up;
                _transform.forward = deltaPos.normalized;
            }

            _transform.position = Vector3.MoveTowards(_transform.position, targetPos, moveSpeed * Time.smoothDeltaTime);
        }

        public override bool IsOnPoint(int pointIndex)
        {
            return ((_transform.position - CastToVec(_pathToFollow[pointIndex])).sqrMagnitude < 0.1f);
        }
    }
}
